package com.cuitrip.business.tripservice;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.cuitrip.business.tripservice.model.CategoryInfo;
import com.cuitrip.business.tripservice.model.ServiceInfo;
import com.cuitrip.component.flowlayout.TagView;
import com.cuitrip.service.R;
import com.cuitrip.util.FlowLayout;
import com.cuitrip.util.ResourceUtil;
import com.lab.app.customui.CustomUiConfig;
import com.lab.app.customui.CustomUiFragment;
import com.lab.jumper.FragmentJumper;
import com.lab.rtenvironment.AppCoreRuntime;
import com.lab.utils.Utils;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by sheena on 16/4/19.
 */
public class CreateTripSucFragment extends CustomUiFragment{

    @Bind(R.id.fl_cates)
    FlowLayout flCates;

    @Bind(R.id.tv_trip_title)
    TextView tvTripTitle;

    @Bind(R.id.tv_trip_city)
    TextView tvTripCity;

    public static final String ARGS_TITLE="title";
    private String title;
    private ServiceInfo serviceInfo;

    public static CreateTripSucFragment newInstance(ServiceInfo serviceInfo){
        CreateTripSucFragment createTripSucFragment = new CreateTripSucFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable(ServiceInfo.KEY,serviceInfo);
        createTripSucFragment.setArguments(bundle);
        return createTripSucFragment;
    }



    @Override
    public boolean initCloseTopBar() {
        return true;
    }

    @Override
    public CustomUiConfig initCustomUiConfig() {
        return null;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (getArguments()!=null){
            title = getArguments().getString(ARGS_TITLE);
            serviceInfo = (ServiceInfo) getArguments().getSerializable(ServiceInfo.KEY);
        }
        View view = super.onCreateView(inflater, container, savedInstanceState, R.layout.fragment_create_suc);
        return view;
    }

    @Override
    public void initView() {
        ButterKnife.bind(this,getView());

    }

    @Override
    public void initData() {

        if (!TextUtils.isEmpty(title)){
            tvTripTitle.setText(title);
        }

        if (serviceInfo!=null){
            String city = serviceInfo.getCity();
            tvTripCity.setText(city);
            List<CategoryInfo> cateList = serviceInfo.cateList;
            if (cateList==null ||cateList.size()==0){
                flCates.setVisibility(View.GONE);
            }else {
                flCates.setVisibility(View.VISIBLE);
                for (CategoryInfo categoryInfo : cateList) {
                    String cateName = categoryInfo.getName();
                    TagView tagView = new TagView(AppCoreRuntime.context, cateName);
                    tagView.setTextSize(13);
                    tagView.setTextColor(ResourceUtil.getColor(R.color.hint));
                    tagView.setBackgroundResource(R.drawable.select_white_corner);
                    flCates.addView(tagView);
                }
            }
        }
    }


    @OnClick(R.id.tv_btn_ok)
    public void navigateCompleteTrip(){
        FragmentJumper.addFragment(getHostActivity().getCustomSelfFragmentManager(),R.id.container,CreateTripEditMainFragment.newInstance(serviceInfo),CreateTripEditMainFragment.class.getName(),true);
    }
}
